#!/usr/bin/env python
""" AnyBackup is a windows specific backup program to keep multiple volumes in sync with multiple volumes
    Copyright (C) 2011  Andrew Hopkinson

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    Exported Classes:
    
    ScrollingProgressDialog -- a dialog window with a progress bar which continually scrolls while the dialog is displayed
    """
    
import wx

class ScrollingProgressDialog(wx.Dialog):
    """ a dialog window with a progress bar which continually scrolls while the dialog is displayed """
    def __init__(self,parent,label):
        wx.Dialog.__init__(self,parent,-1,label,wx.DefaultPosition,wx.Size(200,125),wx.CAPTION|wx.SYSTEM_MENU)
        self.parent=parent
        self.progressBar = wx.Gauge(self,-1,80)
        self.count=0
        self.toAdd=1
        self.cancel = wx.Button(self,1,"Cancel")
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.progressBar,0,wx.EXPAND|wx.ALL,10)
        box.Add(self.cancel,0,wx.ALL|wx.ALIGN_CENTER_HORIZONTAL,5)
        self.SetSizer(box)
        self.timer=wx.Timer(self,0)
        self.timer.Start(30)
        wx.EVT_TIMER(self,0,self.updateGauge)
        wx.EVT_BUTTON(self,1,self.cancelAction)
    
    def cancelAction(self,event):
        wx.CallAfter(self.parent.cancelAction)
        self.Close(1)
        
    def updateGauge(self,event):
        self.count += self.toAdd
        if self.count > 100:
            self.count = 0
        self.progressBar.SetValue(self.count)